from django.db import models

# Create your models here.
from django.db import models
from libs import ModelMixin, human_datetime
from apps.account.models import User


class VpnServer(models.Model, ModelMixin):
    name = models.CharField("VPN名称", max_length=50, unique=True, help_text="VPN名称")
    key = models.CharField(max_length=50)
    url = models.CharField("VPN地址", max_length=50, help_text="VPN地址")
    type = models.CharField("VPN类型", max_length=50, default="pritunl", help_text="VPN类型")
    username = models.CharField("用户名", max_length=50, help_text="用户名")
    password = models.CharField("密码", max_length=50, help_text="密码")
    serverid = models.CharField("服务器组织ID", max_length=50, help_text="服务器组织ID", null=True)
    desc = models.CharField(max_length=255, null=True)

    created_at = models.CharField(max_length=20, default=human_datetime)
    created_by = models.ForeignKey(User, models.PROTECT, related_name='+')
    deleted_at = models.CharField(max_length=20, null=True)
    deleted_by = models.ForeignKey(User, models.PROTECT, related_name='+', null=True)

    def __repr__(self):
        return '<VpnServer %r>' % self.name

    class Meta:
        db_table = 'vpnserver'
        ordering = ('-id',)


class VpnUser(models.Model, ModelMixin):
    email = models.CharField("用户邮箱", max_length=50, help_text="用户邮箱", blank=True)
    name = models.CharField("用户名", max_length=50, help_text="用户名", blank=True)
    userid = models.CharField("用户ID", max_length=50, help_text="用户ID", blank=False)
    vpnserver = models.ForeignKey(VpnServer, on_delete=models.CASCADE, verbose_name="用户所属VPN服务端", help_text="用户所属VPN服务端")
    disabled = models.BooleanField("是否禁用", help_text="是否禁用", default=False)
    desc = models.CharField(max_length=255, null=True)

    created_at = models.CharField(max_length=20, default=human_datetime)
    created_by = models.ForeignKey(User, models.PROTECT, related_name='+')
    deleted_at = models.CharField(max_length=20, null=True)
    deleted_by = models.ForeignKey(User, models.PROTECT, related_name='+', null=True)

    def __repr__(self):
        return '<VpnUser %r-%r>' % (self.name, self.email)

    class Meta:
        db_table = 'vpnuser'
        ordering = ('-id',)
